import {
  exportUrl,
  downloadTemplateUrl,
  getStationCodeList,
  getLineCodeList,
  getListByWorkCellCode,
} from "@/api/sop/mesCoEsopInfo";
import url from "@/axios/url";
import app from "@/main";
import store from "@/store";
import { uniqueKey, checkStr } from "@/utils/judge";
const { mesUrl } = url();
const version = "";
// import {
//   getGoodsList,
// } from "@/api/configuration/mesPmJtmanager";

import { exportExcel } from "@/utils/judge";

// 列表头按钮配置
export const operateList = [
  {
    name: $i18n.t("common.export"),
    type: "primary",
    icon: "el-icon-download",
    handleName: "export", //点击时返回的标识
    url: exportUrl,
    //auth: "auth:operlog:export", //权限字段
  },
  {
    name: $i18n.t("common.add"),
    type: "primary",
    icon: "el-icon-circle-plus-outline",
    handleName: "add", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    icon: "el-icon-delete",
    handleName: "deleteBatch", //点击时返回的标识
    isMultiple: true, // isSingle 表示必须选择一项//isMultiple: true, // 表示必须多选
  },
  // {
  //   name: "导入",
  //   type: "primary",
  //   icon: "el-icon-circle-plus-outline",
  //   handleName: "import", //点击时返回的标识
  // },
];
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", //点击时返回的标识
  },
  {
    name: $i18n.t("common.details"),
    type: "info",
    class: "row-btn-info",
    handleName: "detail", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-danger",
    handleName: "delete", //点击时返回的标识
  },
];
// 搜索条件配置
export const searchConfig = {
  data() {
    const self = this;
    return {
      searchDialog: {
        inline: true,
        formDesc: {
          csiSn: {
            type: "input",
            label: $i18n.t("mesCoEsopInfo.csiSn"),
          },
          csiName: {
            type: "input",
            label: $i18n.t("mesCoEsopInfo.csiName"),
          },
          lineCode: {
            type: "select",
            label: $i18n.t("mesCoEsopInfo.line"),
            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            options: async (data) => {
              const params = {
                modelingCode: this.$store.getters.factoryCode,
                level: 5,
              };
              const list = await getLineCodeList(params);
              return list.data.result;
            },
          },
          workCellCode: {
            type: "select",
            label: $i18n.t("mesCoEsopInfo.station"),
            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            attrs: {
              filterable: true,
            },
            options: async (data) => {
              const params = {
                modelingCode: this.$store.getters.factoryCode,
                level: 6,
              };
              const list = await getStationCodeList(params);
              return list.data.result;
            },
          },
          processName: {
            type: "input",
            label: $i18n.t("mesCoEsopInfo.processName"),
          },
          csiModelCode: {
            type: "input",
            label: $i18n.t("mesCoEsopInfo.csiModelCode"),
          },
          csiVersion: {
            type: "input",
            label: $i18n.t("mesCoEsopInfo.csiVersion"),
          },
        },
      },
    };
  },
};
// 新增/删除表单配置
export const formDescDialogMinxin = {
  data() {
    var validatePass = (rule, value, callback) => {
      setTimeout(() => {
        if (value === undefined || value === null) {
          callback();
        } else {
          if (!checkStr(value, "english-number-")) {
            callback(new Error($i18n.t("mesCoEsopInfo.rule11")));
          } else {
            callback();
          }
        }
      }, 100);
    };
    const self = this;
    return {
      formDescDialog: {
        span: 24,
        disabled: false,
        isShowSubmitBtn: true,
        rules: {
          csiSn: [{ validator: validatePass, trigger: ["change", "blur"] }],
        },
        formDesc: {
          csiSn: {
            type: "input",
            label: $i18n.t("mesCoEsopInfo.csiSn"),
            layout: 12,
            disabled: (data) => {
              return !!data.codeStrategy || !!data.id;
            },
          },
          csiName: {
            type: "input",
            label: $i18n.t("mesCoEsopInfo.csiName"),
            layout: 12,
            required: true,
          },
          lineCode: {
            type: "select",
            label: $i18n.t("mesCoEsopInfo.line"),
            layout: 12,
            required: false,
            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            options: async (data) => {
              const params = {
                modelingCode: this.$store.getters.factoryCode,
                level: 5,
              };
              const list = await getStationCodeList(params);
              return list.data.result;
            },
          },
          workCellCode: {
            type: "select",
            label: $i18n.t("mesCoEsopInfo.station"),
            layout: 12,
            required: false,
            disabled: (data) => {
              return data.lineCode ? false : true;
            },
            optionsLinkageFields: ["lineCode"],
            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            options: async (data) => {
              if (data.lineCode) {
                const params = {
                  modelingCode: data.lineCode,
                  level: 6,
                };
                const list = await getStationCodeList(params);
                return list.data.result;
              } else {
                return [];
              }
            },
            on: {
              change: async (val) => {
                console.log("val", val);
                if (val) {
                  const result = await getListByWorkCellCode(val);
                  self.$set(
                    self.formDataDialog,
                    "processName",
                    result.data.result.processName || ""
                  );
                  self.$set(
                    self.formDataDialog,
                    "processCode",
                    result.data.result.processCode || ""
                  );
                } else {
                  self.$set(self.formDataDialog, "processName", "");
                  self.$set(self.formDataDialog, "processCode", "");
                }

                // console.log('name', result.data.result)
              },
            },
          },
          processName: {
            type: "input",
            label: $i18n.t("mesCoEsopInfo.processName"),
            layout: 12,
            required: false,
            disabled: true,
          },
          processCode: {
            type: "input",
            label: $i18n.t("mesCoEsopInfo.processCode"),
            layout: 12,
            required: false,
            disabled: true,
            visible: false,
          },
          csiModelCode: {
            type: "input",
            label: $i18n.t("mesCoEsopInfo.csiModelCode"),
            layout: 12,
            required: false,
          },
          csiModelName: {
            type: "input",
            label: $i18n.t("mesCoEsopInfo.csiModelName"),
            layout: 12,
            required: false,
            disabled: true,
          },
          csiModelSpecification: {
            type: "input",
            label: $i18n.t("mesCoEsopInfo.csiModelSpecification"),
            layout: 12,
            disabled: true,
            required: false,
          },
          // csiModelCode: {
          //   type: "input",
          //   label: "物料",
          //   layout: 12,
          //   required: true,
          //   prop: {
          //     value: "goodsCode",
          //     text: "goodsName",
          //   },
          //   options: async () => {
          //     const list = await getGoodsList();
          //     const data = list.data.result;
          //     console.log(data);
          //     self.prodCodeList = data;
          //     return data;
          //   },
          // },
          csiVersion: {
            type: "input",
            label: $i18n.t("mesCoEsopInfo.csiVersion"),
            layout: 24,
            required: true,
            on: {
              blur: (data) => {
                this.version = this.formDataDialog.csiVersion;
                console.log(this.version);
              },
            },
          },
          csiDefaultFlag: {
            label: $i18n.t("mesCoEsopInfo.csiDefaultFlag"),
            layout: 12,
            required: false,
            type: "switch",
            //提交时将true 转化为1 false 0
            valueFormatter(labels) {
              return labels;
            },
            attrs: {
              activeValue: "1",
              inactiveValue: "0",
            },
            //展示时字段转化
            // displayFormatter(labels) {
            //   return labels == "Y" ? true : false;
            // },
          },
          csiValidFlag: {
            label: $i18n.t("mesCoEsopInfo.csiValidFlag"),
            layout: 12,
            required: false,
            type: "switch",
            //提交时将true 转化为1 false 0
            valueFormatter(labels) {
              console.log("有效标志", labels);
              return labels;
            },
            attrs: {
              activeValue: "1",
              inactiveValue: "0",
            },
            //展示时字段转化
            // displayFormatter(labels) {
            //   return labels == "Y" ? true : false;
            // },
          },
          csiProcessFileNameEntity: {
            type: "upload-file",
            label: $i18n.t("mesCoEsopInfo.csiProcessFileNameEntity"),
            layout: 24,
            required: false,
            attrs: {
              beforeUpload() {
                console.log(11111111);
              },
              autoUpload: true,
              limit: 1,
              fileType: [
                "png",
                "jpg",
                "jpeg",
                "xls",
                "pdf"
              ],
              action: `${mesUrl}coFile/uploadExcel`,
              data: {
                bucket: "messervice",
                // version:
              },
              headers: {
                Satoken: store.getters.token,
              },
              responseFn(response, file) {
                if (response.code === 0) {
                  return {
                    name: file.name,
                    size: file.size,
                    id: response.result,
                  };
                }
              },
            },
          },
          csiFileNameEntity: {
            type: "upload-file",
            label: $i18n.t("mesCoEsopInfo.csiFileNameEntity"),
            layout: 24,
            required: false,
            attrs: {
              beforeUpload() {
                console.log(11111111);
              },
              autoUpload: true,
              limit: 1,
              fileType: ["png", "jpg", "jpeg", "xls", "pdf", "mp4"],
              action: `${mesUrl}coFile/uploadExcel`,
              data: {
                bucket: "messervice",
                // version:
              },
              headers: {
                Satoken: store.getters.token,
              },
              responseFn(response, file) {
                if (response.code === 0) {
                  return {
                    name: file.name,
                    size: file.size,
                    id: response.result,
                  };
                }
              },
            },
          },
          remark: {
            type: "textarea",
            label: $i18n.t("common.remark"),
            layout: 24,
            required: false,
          },
          // sopFrockList: {
          //   type: "table-editor",
          //   label: $i18n.t("mesCoEsopInfo.sopFrockList"),
          //   layout: 24,
          //   required: false,
          //   attrs: {
          //     // 上方,按钮,render
          //     topBtnRender: (h, solt) => {
          //       return (
          //         <el-button
          //           type="primary"
          //           onClick={() => {
          //             this.addList();
          //           }}
          //         >
          //           {$i18n.t("common.add")}
          //         </el-button>
          //       );
          //     },
          //     isShowAdd: false,
          //     // 表格列
          //     columns: [
          //       {
          //         type: "index",
          //         width: 50,
          //       },
          //       {
          //         prop: "frockCode",
          //         label: $i18n.t("mesCoEsopInfo.frockCode"),
          //       },
          //       {
          //         prop: "frockName",
          //         label: $i18n.t("mesCoEsopInfo.frockName"),
          //       },
          //     ],
          //   },
          // },
        },
      },
    };
  },
  methods: {
    addList() {
      this.frockDialogVisible = true;
    },
  },
};
//导入数据
export const importFormDescDialog = {
  span: 24,
  disabled: false,
  isShowSubmitBtn: true,
  formDesc: {
    model: {
      type: "button",
      label: "",// $i18n.t("mesCoEsopInfo.model"),
      layout: 24,
      required: false,
      title: $i18n.t("common.downloadTemplate"),
      style: {
        color: "#1867c0",
        fontSize: "14px",
      },
      on: {
        click: () => {
          exportExcel(downloadTemplateUrl);
        },
      },
    },
    file: {
      type: "input",
      label: $i18n.t("common.chooseFile"),
      layout: 24,
      // required: true,
    },
  },
};
